// deviceInformation.js
const app = getApp()
Page({

  data: {
    deviecBrand: '',//请输入设备品牌
    machineryType: '', //机械类型（1-9对应挖掘机、装载机、矿用自卸车、推土机、压路机、平地机、混凝土机械、桩工机械、凿岩机械）
    dateOfProduction:'',  //出厂日期

    array: ['', '挖掘机', '装载机', '矿用自卸车', '推土机', '压路机', '平地机', '混凝土机械', '桩工机械', '凿岩机械'],//picker选择项
    index: '1',//picker组件的角标

    identification:'', //所属的单位
    plateSubject: '',//请输入设备型号
    machineryColour: '',//请输入机械颜色
    engineSubject: '',//请输入发动机型号
    maneuver:'',//行走方式
    power: '',//请输入发动机功率
    resBuyDate: '',//购买日期
    enginePlateNum: '',//请输入发动机编号
    productionAddress: '',//请输入设备产地
    workTime: '',//请输入设备工作小时
    weight: '',//请输入整机重量
    outputVolume: '',//请输入尾气排放值
    factoryNum: '',//出厂编号
    productionType: '',//生产方式（0国产，1合资，2进口）
    fuel:'', //燃料类型
    accept: false
  },

  bindPickerChange: function (e) {
    this.setData({
      index: e.detail.value
    })
  },
  accept: function (e) {
    if (e.detail.value == '0') {
      this.setData({
        accept: true
      })
    } else {
      this.setData({
        accept: false
      })
    }
  },

  submit: function (e) {
    var that = this;
    var identification = that.data.identification;
    var deviecBrand = e.detail.value.deviecBrand;
    var machineryType = e.detail.value.machineryType;
    var dateOfProduction = e.detail.value.dateOfProduction;
    var plateSubject = e.detail.value.plateSubject;
    var machineryColour = e.detail.value.machineryColour;
    var engineSubject = e.detail.value.engineSubject;
    var maneuver = e.detail.value.maneuver;
    var power = e.detail.value.power;
    var resBuyDate = e.detail.value.resBuyDate;
    var enginePlateNum = e.detail.value.enginePlateNum;
    var productionAddress = e.detail.value.productionAddress;
    var workTime = e.detail.value.workTime;
    var weight = e.detail.value.weight;
    var outputVolume = e.detail.value.outputVolume;
    var factoryNum = e.detail.value.factoryNum;
    var productionType = e.detail.value.productionType;
    var fuel = e.detail.value.fuel;

    wx.request({
      url: 'https://www.gcjxglzx.com/deviceInformation/save',
      data: {
        identification: identification,
        deviecBrand: deviecBrand,
        machineryType: machineryType,
        dateOfProduction: dateOfProduction,
        plateSubject: plateSubject,
        machineryColour: machineryColour,
        engineSubject: engineSubject,
        maneuver: maneuver,
        power: power,
        resBuyDate: resBuyDate,
        enginePlateNum: enginePlateNum,
        productionAddress: productionAddress,
        workTime: workTime,
        weight: weight,
        outputVolume: outputVolume,
        factoryNum: factoryNum,
        productionType: productionType,
        fuel: fuel
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      method: 'POST',
      success: function (res) {
        console.log(res.data)
        if (res.data.status=='0'){
          //并缓存设备出场编号和用户身份证号
          wx.setStorageSync("factoryNum", factoryNum);
          wx.navigateTo({
            url: '/page-deviceInformationImg/home'
          })
        }
      }
    })

  },

  dateOfProduction: function (e) {
    this.setData({
      dateOfProduction: e.detail.value
    })
  },
  resBuyDate: function (e) {
    this.setData({
      resBuyDate: e.detail.value
    })
  },


  onLoad: function (options) {
    var that = this;
    that.setData({
      identification:wx.getStorageSync('identification')
    })
  },



  onReady: function () {

  },

  onShow: function () {

  },


  onHide: function () {

  },

  onUnload: function () {

  },

  onPullDownRefresh: function () {

  },


  onReachBottom: function () {

  },

  onShareAppMessage: function () {

  }
})